﻿package  
{
	
	/**
	 * ...
	 * @author ...
	 */
	public class camera 
	{
		public var pos:cartesian;
		public var zoom:Number = 2;
		public var tzoom:Number = 0.6;
		
		public function camera() 
		{
			pos = new cartesian(0, 0);
		}
		
		public function update(car:vehicle):void
		{
			pos.x = pos.x + (car.getMeanPos().x - pos.x) / 5;
			pos.y = pos.y + (car.getMeanPos().y - pos.y) / 5;
			
			this.zoom = this.zoom + (this.tzoom - this.zoom) / 5;
			
			if (isNaN(pos.x) || isNaN(pos.y))
			{
				trace("Camera NAN!");
				
				pos.x = 0;
				pos.y = 0;
				this.zoom = 1;
			}
			
			if (isNaN(this.zoom))
			{
				trace("Zoom NaN!");
				this.zoom = 1;
			}
			
		}
		
		public function adjustZoom(tdelta:Number)
		{
			tzoom += tdelta;
			if (tzoom < .4)
			{
				tzoom = .4; // Min Zoom
			}
			if (tzoom > 3)
			{
				tzoom = 3; // Max Zoom
			}
		}
		
	}
	
}